<template>
	<view >
  <view class="card-content" v-for="squareContent in contentList" >
    <view class="card-header" style="flex:1">
      <!-- 头像 -->
      <u-avatar
        src="https://cmtq-1317574530.cos.ap-guangzhou.myqcloud.com/img2023/myIcon/head.png"
        show-sex
        sex-icon="woman"
        show-level
		v-if="squareContent.head==null||squareContent.head==''"
        >
      </u-avatar>
	  <u-avatar
	    :src="squareContent.head"
	    show-sex
	    sex-icon="woman"
	    show-level
	  		v-else
	    >
	  </u-avatar>
      <!-- 昵称和时间 -->
      <view class="card-right" style="flex:6">
        <view class="right-top-name">{{squareContent.nichen}}
		 <u-image v-if="squareContent.sex=='女'" src="https://cmtq-1317574530.cos.ap-guangzhou.myqcloud.com/2024/images/w.png" width="30rpx" height="30rpx" style="margin-left:20rpx"/>
		 <u-image v-else src="https://cmtq-1317574530.cos.ap-guangzhou.myqcloud.com/2024/images/m.png" width="30rpx" height="30rpx" style="margin-left:20rpx"/>
		 </view>
        <view class="header-right-bottom">
          {{squareContent.createTime}}
          <text class="header-right-info">
           <!-- <text class="header-right-point">·</text> -->
          </text>
        </view>
      </view>
	  <view v-if="isDelete==1" @click="delSquare(squareContent)">
		  <uni-icons type="trash-filled"  size="25"></uni-icons>
	  </view>
    </view>
    <!-- 内容 -->
    <view class="card-body">
      <view class="card-body-text">
        {{squareContent.msg}}
      </view>
      <!-- 图片 -->
      <view class="card-body-img-col3" v-if="squareContent.url!=null&&squareContent.url!=''">
        <view class="card-body-img-col3-item" v-for="item in splitImgArr(squareContent.url)" :key="item">
          <view v-for="item2 in item" :key="item2">
            <u-image radius="15" @click="showPic(squareContent.url,item2)" width="100%" height="220rpx" :src="item2"></u-image>
          </view>
        </view>
      </view>
    </view>
    <!-- address -->
    <view class="address" v-if="squareContent.school">
      <u-icon name="map-fill" class="map-icon" color="#2979ff"></u-icon>
      <span color="#2979ff" >{{squareContent.school}}</span>
    </view>
    <!-- 点赞 评论 转发 -->
    <view class="card-foot">
      <view class="card-foot-item" @click="shareWx()">
        <u-image src="https://cmtq-1317574530.cos.ap-guangzhou.myqcloud.com/2024/images/zf.png" width="44rpx" height="44rpx"/>
        <text class="card-foot-item-text">转发</text>
      </view>
	  <view class="card-foot-item" @click="coll(squareContent)">
	    <u-image  v-if="squareContent.isColl==0"  src="https://cmtq-1317574530.cos.ap-guangzhou.myqcloud.com/2024/img/wsc.png" width="50rpx" height="50rpx"/>
	  		<u-image  v-else  src="https://cmtq-1317574530.cos.ap-guangzhou.myqcloud.com/2024/img/ysc.png" width="50rpx" height="50rpx"/>
	    <text class="card-foot-item-text">收藏</text>
	  </view>
      <view v-if="isPl==1" class="card-foot-item" @click="showDetail(squareContent)">
        <u-image src="https://cmtq-1317574530.cos.ap-guangzhou.myqcloud.com/2024/images/pl.png" width="50rpx" height="50rpx"/>
        <text class="card-foot-item-text">{{squareContent.commentNum}}</text>
      </view>
	  <view v-else class="card-foot-item" >
	    <u-image src="https://cmtq-1317574530.cos.ap-guangzhou.myqcloud.com/2024/images/pl.png" width="50rpx" height="50rpx"/>
	    <text class="card-foot-item-text">{{squareContent.commentNum}}</text>
	  </view>
      <view class="card-foot-item" @click="like(squareContent)">
        <u-image  v-if="squareContent.isLike==0"  src="https://cmtq-1317574530.cos.ap-guangzhou.myqcloud.com/2024/images/dz.png" width="50rpx" height="50rpx"/>
		<u-image  v-else  src="https://cmtq-1317574530.cos.ap-guangzhou.myqcloud.com/2024/images/ydz.png" width="50rpx" height="50rpx"/>
        <text class="card-foot-item-text">{{squareContent.likeNum}}</text>
      </view>
    </view>
  </view>
  </view>
</template>

<script>
import config from "@/config/index.config.js";
export default {
  name: 'schoolCard',
  props: {
	  contentList:Array,
	  isPl:{
		  type:Number,
		  default:1
	  },
	  isDelete:{ //布局格式，长方形oblong，正方形square
				type: Number,
				default: 0
			},
  },
  components: {
  },
  data() {
    return {
      
      zhuanfa: '',
      pinglun: '',
		}
  },
//发送给朋友
  onShareAppMessage(res) {
    let that = this;
    return {
      title: '星城校园',
      path: '/pages/index/index?pcode=' + that.userInfo.pcode,
      imageUrl:
        'https://cmtq-1317574530.cos.ap-guangzhou.myqcloud.com/banner/%E7%94%BB%E6%9D%BF%203.png',
      success(res) {
        console.log('success(res)==', res);
        uni.showToast({
          title: '分享成功',
        });
      },
      fail(res) {
        console.log('fail(res)==', res);
        uni.showToast({
          title: '分享失败',
          icon: 'none',
        });
      },
    };
  },
  //分享到朋友圈
  onShareTimeline(res) {
    let that = this;
    return {
      title: '找兼职/找工作，海量岗位放心选',
      path: '/pages/index/index?pcode=' + that.userInfo.pcode,
      imageUrl:
        'https://cmtq-1317574530.cos.ap-guangzhou.myqcloud.com/banner/%E7%94%BB%E6%9D%BF%203.png',
      success(res) {
        console.log('success(res)==', res);
        uni.showToast({
          title: '分享成功',
        });
      },
      fail(res) {
        console.log('fail(res)==', res);
        uni.showToast({
          title: '分享失败',
          icon: 'none',
        });
      },
    };
  },
  methods: {
	  delSquare(data){
		  this.$emit("squareDel",data)
	  },
	  splitImgArr (data) {
	    let result = []
	    for(let i = 0; i < data.length; i += 3){
	      result.push(data.slice(i, i + 3))
	    }
	    return result
	  },
	  showDetail (data) {
		  console.log(this.isPl)
	    uni.navigateTo({
	      url: '/pages/myManage/schoolSquare/schoolDetail?data='+ JSON.stringify(data)
	    })
	  },
	  shareWx(){
		  console.log("123")
		  var that=this
		  uni.share({
		  	  title: '星城校园',
		  	  path: '/pages/index/index',
		  	  imageUrl:
		  	    'https://cmtq-1317574530.cos.ap-guangzhou.myqcloud.com/banner/%E7%94%BB%E6%9D%BF%203.png',
		  	  success(res) {
		  	    uni.showToast({
		  	      title: '分享成功',
		  	    });
		  	  },
		  	  fail(res) {
		  	    console.log('fail(res)==', res);
		  	    uni.showToast({
		  	      title: '分享失败',
		  	      icon: 'none',
		  	    });
		  	  },
		  	
		  })
	  },
	  coll(item){
		  var query={
			  id:item.id,
			  type:1
		  }
		  var url='circleLikeAdd';
		  var msg='收藏成功'
		  if(item.isColl==1){
			  url='circleLikeRm';
			  msg='取消收藏成功'
		  }
		  uni.request({
		  	url: `${config.baseUrl}/starCityAll/circle/`+url,
		  	method: "GET",
		  	data: query,
		  	dataType: "json",
		  	header: {
		  		"content-type": "application/json",
		  		"Blade-Auth":uni.getStorageSync("token")
		  	},
		  	success: (res) => {
				if(res.data.code==0){
					item.isColl=(item.isColl+1)%2;
					console.log()
					uni.showToast({
					  title:  msg,
					  icon: 'none',
					});
				}
		  	}
		  
		  })
	  },
	  like(item){
	  		  var query={
	  			  id:item.id,
	  			  type:0
	  		  }
	  		  var url='circleLikeAdd';
	  		  var msg='点赞成功'
	  		  var num=1;
	  		  if(item.isLike==1){
	  			  url='circleLikeRm';
	  			  msg='取消点赞成功'
	  			  num=-1;
	  		  }
	  		  uni.request({
	  		  	url: `${config.baseUrl}/starCityAll/circle/`+url,
	  		  	method: "GET",
	  		  	data: query,
	  		  	dataType: "json",
	  		  	header: {
	  		  		"content-type": "application/json",
	  		  		"Blade-Auth":uni.getStorageSync("token")
	  		  	},
	  		  	success: (res) => {
	  				if(res.data.code==0){
	  					item.isLike=(item.isLike+1)%2;
	  					console.log()
	  					item.likeNum+=num;
	  					uni.showToast({
	  					  title:  msg,
	  					  icon: 'none',
	  					});
	  				}
	  		  	}
	  		  
	  		  })
	  },
	  showPic(imgList,imgSrc) {
	    uni.previewImage({
	      indicator: 'none',
	      current: imgSrc,
	      urls: imgList
	    })
	  }
  },
};
</script>

<style lang="scss" scoped>
  .card-content {
    width: 720rpx;
    display: flex;
    flex-direction: column;
	border-bottom:15rpx solid #eee;
    .card-header {
      padding: 20rpx;
      display: flex;
      flex-direction: row;
      .card-right {
        padding-left: 10rpx;
      }
    }
    .right-top-name {
		display: flex;
      color: #222;
	  //justify-content: center;
	  align-items: center;
      font-family: PingFangSC-Medium;
      font-size: 30rpx;
    }
    .header-right-bottom {
      margin-top: 4rpx;
      font-size: 20rpx;
      line-height: 10rpx;
      color: #999;
      .header-right-info {
        .header-right-point {
          display: inline-block;
          padding: 10rpx;
          font-weight: 700;
        }
      }
    }
    .card-body {
      .card-body-text {
		  white-space:normal;
		  overflow-wrap: break-word;
        font-size: 30rpx;
        line-height: 40rpx;
        padding: 0 20rpx;
        margin-bottom: 20rpx;
      }
      .card-body-img-col1 {
         width: 700rpx;
		 margin:0 10rpx;
      }
      .card-body-img-col3 {
        width: 700rpx;
        .card-body-img-col3-item {
          width: 700rpx;
		  margin:0 10rpx;
          display: flex;
          flex-direction: row;
          >view {
            width: 250rpx;
            margin: 5rpx;
          }
        }
      }
    }
    .card-foot {
      display: flex;
      flex-direction: row;
      justify-content: space-around;
      padding: 20rpx 0;
      .card-foot-item {
        display: flex;
        flex-direction: row;
        justify-content: center;
        align-items: center;
        text {
          color: #222;
		  font-weight: bold;
          font-size: 28rpx;
		  margin-left:30rpx;
        }
      }
    }
    .address {
      margin-left: 20rpx;
      margin-top: 20rpx;
	  display:flex;
      .map-icon {
        margin-right: 10rpx;
      }
    }
  }
</style>
